package com.xrjsj.stage.exception;

import com.xrjsj.stage.bean.common.ResultBean;
import com.xrjsj.stage.constant.CommonEnum.ResultInfo;
import com.xrjsj.stage.util.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value=Exception.class)
    @ResponseBody
    public ResultBean handle(Exception e){
        if(e instanceof CommonException){
            CommonException exception = (CommonException)e;
            return ResultUtil.error(exception.getCode(), exception.getMessage());
        }
        return ResultUtil.error(ResultInfo.UNKOWN_ERROT.getCode(), e.getMessage());
    }
}
